
#pragma once

#include <dbt.h>
#include "hidsdi.h"
#include "hid.h"
#include "setupapi.h"
#include "usb100.h"

#pragma comment(lib, "hid.lib")
#pragma comment(lib, "setupapi.lib")


#define	UM_HID_PACKET	(WM_USER + 0x100)	// wParam(dwCount), lParam(pPacket)


class CHidCtrl
{
public:
	CHidCtrl(void);
	~CHidCtrl(void);

	// afx_msg BOOL OnDeviceChange(UINT nEventType, DWORD_PTR dwData);	// ON_WM_DEVICECHANGE()
	BOOL RegDevNotify(HWND hWndNotify);
	void UnregDevNotify(void);

	BOOL IsOpen(void);
	BOOL OpenDevice(WORD wVid, WORD wPid, BYTE bIfn, LPSTR lpString=NULL, int nCount=0);
	void CloseDevice(void);

	BOOL RecvThreadProc(PBYTE pBuf, DWORD dwCount);

	DWORD SendReport(PBYTE pBuf, DWORD dwCount);

private:
	HWND		m_hWndNotify;
	HDEVNOTIFY	m_hDeviceNotify;

	HANDLE		m_hDeviceSend;
	HANDLE		m_hDeviceRecv;
	HANDLE		m_hEventCompletion;
	OVERLAPPED	m_OverlapRecv;
	HANDLE		m_hThreadRecv;
};
